<?php
class PppsController extends AppController {

	var $name = 'Ppps';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Ppp->recursive = 0;
		$this->set('ppps', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Ppp.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('ppp', $this->Ppp->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Ppp->create();
			if ($this->Ppp->save($this->data)) {
				$this->Session->setFlash(__('The Ppp has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Ppp could not be saved. Please, try again.', true));
			}
		}
		$funcionarios = $this->Ppp->Funcionario->find('list');
		$agentesriscos = $this->Ppp->Agentesrisco->find('list');
		$tecnicas = $this->Ppp->Tecnica->find('list');
		$gfips = $this->Ppp->Gfip->find('list');
		$this->set(compact('funcionarios', 'agentesriscos', 'tecnicas', 'gfips'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Ppp', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Ppp->save($this->data)) {
				$this->Session->setFlash(__('The Ppp has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Ppp could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Ppp->read(null, $id);
		}
		$funcionarios = $this->Ppp->Funcionario->find('list');
		$agentesriscos = $this->Ppp->Agentesrisco->find('list');
		$tecnicas = $this->Ppp->Tecnica->find('list');
		$gfips = $this->Ppp->Gfip->find('list');
		$this->set(compact('funcionarios','agentesriscos','tecnicas','gfips'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Ppp', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Ppp->del($id)) {
			$this->Session->setFlash(__('Ppp deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>